李守中

FreeIPA 在 Rocky8 上的部署、备份与恢复

Table of Contents

1. 环境说明

FreeIPA 中的 A (Audit) 部分还不是很完善,但是一直在改进中,I 和 P 部分做得很好,适合作为企业内部的基础设施。

IP HostName Descprition
192.168.2.98/24 a.ipa.test.local master
192.168.2.97/24 b.ipa.test.local replica
  • 所有机器使用内置 DNS:
    • 开启 DNS 转发
    • 上游 DNS 为自建的 192.168.2.10
  • 后续命令由 root 用户执行
  • 建议使用三级域名
  • FreeIPA Server 所在主机的 IP 的子网掩码不能是 /32, 至少是 /24
  • 默认启动防火墙

注: 如果在 FreeIPA Server 所在的机器上使用 bind 作为 DNS 服务,则 FreeIPA Server 所在的每台机器都需要安装 bind 并组成集群;而 FreeIPA 内置了一个 DNS,可以把集群配置自动化,还有 WebUI 可以统一管理,比较方便。所以,部署 FreeIPA 时使用内置的 DNS 服务。

2. 部署 Master 节点

2.1. 确定上游 DNS 能解析到两台机器的 IP

dnf install -y bind-utils 安装 DNS 工具用于测试 DNS 是否正常:

# 在两台机器上分别执行以下两条命令,确定可以从 DNS 解析到 IP
$ dig +short a.ipa.test.local A
192.168.2.98
$ dig +short b.ipa.test.local A
192.168.2.97

2.2. 在 /etc/hosts 中添加主机名和 IP 的映射

在 /etc/hosts 中添加一条:

192.168.2.98 a.ipa.test.local

2.3. 安装 ipa server 初始化工具

Rocky8 的 FreeIPA 服务端和客户端的包在 AppStream 仓库中:

$ yum module list idm
Last metadata expiration check: 0:25:00 ago on Sun 14 May 2023 04:41:58 PM CST.
appstream
Name      Stream         Profiles                                     Summary
idm       DL1            adtrust, client, common [d], dns, server     The Red Hat Enterprise Linux Identity Management system module
idm       client [d]     common [d]                                   RHEL IdM long term support client module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

dnf module info idm:DL1 可以查看这个模块的具体信息。

安装 FreeIPA 服务端需要使用 idm:DL1 这个模块: dnf module enable -y idm:DL1

可以看到 DL1 这个 Stream 已被启用:

$ yum module list idm
Last metadata expiration check: 0:33:43 ago on Sun 14 May 2023 04:41:58 PM CST.
appstream
Name      Stream         Profiles                                     Summary
idm       DL1 [e]        adtrust, client, common [d], dns, server     The Red Hat Enterprise Linux Identity Management system module
idm       client [d]     common [d]                                   RHEL IdM long term support client module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

安装带有内置 DNS 的 FreeIPA Server: dnf module install idm:DL1/dns

注: 用 dnf install ipa-server ipa-server-dns 也行。和 module install 的区别是,module install 安装的包中包含 ipa-healthcheck-core 和 ipa-healthcheck 两个包,而这条命令安装的包中只包含了 ipa-healthcheck-core 一个。

使用以下参数安装 server:

ipa-server-install \
    --domain ipa.test.local \
    --realm ipa.test.local \
    --reverse-zone=2.168.192.in-addr.arpa. \
    --forwarder=192.168.2.10 \
    --ntp-server=ntp.test.local \
    --setup-dns \
    --ds-password <ds-passwd> \
    --admin-password <admin-passwd> \
    --unattended

注: 执行 ipa-server-install ... 不带 --unattended 参数则会启动交互式安装过程,所需的参数需要用户手动输入。

安装开始前会展示用户输入的配置:

The log file for this installation can be found in /var/log/ipaserver-install.log
==============================================================================
This program will set up the IPA Server.
Version 4.9.10

This includes:
  * Configure a stand-alone CA (dogtag) for certificate management
  * Configure the NTP client (chronyd)
  * Create and configure an instance of Directory Server
  * Create and configure a Kerberos Key Distribution Center (KDC)
  * Configure Apache (httpd)
  * Configure DNS (bind)
  * Configure SID generation
  * Configure the KDC to enable PKINIT

Warning: skipping DNS resolution of host servera.ipa.jggroup.cn
Checking DNS domain ipa.jggroup.cn., please wait ...
Checking DNS domain 2.168.192.in-addr.arpa., please wait ...
Checking DNS forwarders, please wait ...
DNS server 192.168.2.10 does not support DNSSEC: answer to query '. SOA' is missing DNSSEC signatures (no RRSIG data)
Please fix forwarder configuration to enable DNSSEC support.

DNS server 192.168.2.10: answer to query '. SOA' is missing DNSSEC signatures (no RRSIG data)
Please fix forwarder configuration to enable DNSSEC support.
WARNING: DNSSEC validation will be disabled
Checking DNS domain 2.168.192.in-addr.arpa., please wait ...
Using reverse zone(s) 2.168.192.in-addr.arpa.
Trust is configured but no NetBIOS domain name found, setting it now.

The IPA Master Server will be configured with:
Hostname:       a.ipa.test.local
IP address(es): 192.168.2.98
Domain name:    ipa.test.local
Realm name:     IPA.TEST.LOCAL

The CA will be configured with:
Subject DN:   CN=Certificate Authority,O=IPA.TEST.LOCAL
Subject base: O=IPA.TEST.LOCAL
Chaining:     self-signed

BIND DNS server will be configured to serve IPA domain with:
Forwarders:       192.168.2.10
Forward policy:   only
Reverse zone(s):  2.168.192.in-addr.arpa.

NTP server:     ntp.test.local
Disabled p11-kit-proxy
Synchronizing time
Configuration of chrony was changed by installer.
Attempting to sync time with chronyc.
Time synchronization was successful.
......

注意 DNS server 192.168.2.10 does not support DNSSEC: answer to query '. SOA' is missing DNSSEC signatures (no RRSIG data) 这句表示上游服务器不支持 DNSSEC 这个功能,FreeIPA 安装完成后会在 /etc/named/ipa-options-ext.conf 中加入 dnssec-validation no; 配置。

看到以下输出即为安装成功:

==============================================================================
Setup complete

Next steps:
        1. You must make sure these network ports are open:
                TCP Ports:
                  * 80, 443: HTTP/HTTPS
                  * 389, 636: LDAP/LDAPS
                  * 88, 464: kerberos
                  * 53: bind
                UDP Ports:
                  * 88, 464: kerberos
                  * 53: bind
                  * 123: ntp

        2. You can now obtain a kerberos ticket using the command: 'kinit admin'
           This ticket will allow you to use the IPA tools (e.g., ipa user-add)
           and the web user interface.

Be sure to back up the CA certificates stored in /root/cacert.p12
These files are required to create replicas. The password for these
files is the Directory Manager password
The ipa-server-install command was successful

最后一步打开防火墙:

firewall-cmd --add-service={ntp,dns,freeipa-4}
firewall-cmd --add-service={ntp,dns,freeipa-4} --permanent

cat /usr/lib/firewalld/services/freeipa-4.xml 可以看到 freeipa-4 这个 service 中包含的 service 有:

...
<!-- CRL and OCSP -->
<include service="http"/>
<!-- API and web UI -->
<include service="https"/>

<include service="kerberos"/>
<include service="kpasswd"/>
<include service="ldap"/>
<include service="ldaps"/>
...

这些服务对应的端口为:

  • HTTP/HTTPS: 80/tcp, 443/tcp
  • LDAP/LDAPS: 389/tcp, 636/tcp
  • Kerbros: 88/tcp, 88/udp
  • kpasswd: 464/tcp, 464/udp
  • DNS: 53/tcp, 53/udp
  • NTP: 123/udp

访问 a.ipa.test.local 即可登录 WebUI。

3. 部署 Replica 节点

3.1. 在 Master 上给 Replica 配置 Reverse DNS

ipa dnsrecord-add ipa.test.local --a-create-reverse --a-rec 192.168.2.97 b

3.2. 在新节点上安装 Client 并将 Client 注册到 Master

dnf -y install freeipa-client 安装 client 包。

正常的输出长这样:

$ ipa-client-install
This program will set up IPA client.
Version 4.9.10

Discovery was successful!
Do you want to configure chrony with NTP server or pool address? [no]: yes
Enter NTP source server addresses separated by comma, or press Enter to skip: ntp.test.local
Enter a NTP source pool address, or press Enter to skip:
Client hostname: b.ipa.test.local
Realm: IPA.TEST.LOCAL
DNS Domain: ipa.test.local
IPA Server: a.ipa.test.local
BaseDN: dc=ipa,dc=test,dc=local
NTP server: ntp.test.local

Continue to configure the system with these values? [no]: yes
...
User authorized to enroll computers: admin
Password for [email protected]: 这里填安装 Master 时指定的 <admin-passwd>
...
Client configuration complete.
The ipa-client-install command was successful

注意第 5 行的输出。 Discovery 这个 Feature 对应的描述在 man ipa-client-install 里的 DNS Autodiscovery 一节中可以找到。简单来说,这个功能会让 client 自动寻找 ipa.test.local 域名下的 server 端,使得当 client 所连接的 server 掉线时,client 能自动连接到其他在线的 server 上。 这里一定要显示 Discovery 配置成功后再继续下个步骤。

ipa-client-install --mkhomedir 可以让用户在登入时由系统自动创建用户的家目录。如果在 client 初始化时没有带 --mkhomedir 参数的话,也可以用以下命令打开这个功能:

authselect enable-feature with-mkhomedir
systemctl enable --now oddjobd.service

执行到这里就足够了,下个步骤在下一节。 下面的内容是一些补充说明。

如果 Replica 所在的环境中已经有一个 LDAP 服务,而 Master (192.168.2.98) 的地址又不是 DNS 列表中的第一项,则安装命令的输出可能长这样,并且执行时间可能比较长:

$ ipa-client-install
This program will set up IPA client.
Version 4.9.10

Skip ldap2.test.local: LDAP server is not responding, unable to verify if this is an IPA server
Skip ldap1.test.local: LDAP server is not responding, unable to verify if this is an IPA server
Error checking LDAP: Operations error: 000004DC: LdapErr: DSID-0C090A7D, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v3839
Discovery was successful!
Do you want to configure chrony with NTP server or pool address? [no]:

注意第 5-7 的输出。5,6 行输出表示 test.local 域名下其他的 LDAP 服务被 FreeIPA 检测到了,然后 FreeIPA 尝试判断它们是不是 IPA 服务器,结果发现不是,就跳过这几台机器。这个过程会消耗大量的时间。寻找 IPA 服务器的过程中发送了不能操作现有 LDAP API 的请求,所以有了第 7 行的报错。 这些报错不是在说 FreeIPA 有问题,不用管。

此外,如果用户不使用 Autodiscovery,则也可以指定 --domain 之后,使用 --server 多次来指定多个 server 以使 client 的 failover (故障转移) 生效。但需要注意,需要指定多于一个的 server 地址才能使 failover 生效。如果只指定了一个 server,则 failover 依旧不会生效:

$ ipa-client-install --domain ipa.local.test --server=a.ipa.local.test
This program will set up IPA client.
Version 4.9.10

Autodiscovery of servers for failover cannot work with this configuration.
If you proceed with the installation, services will be configured to always access the discovered server for all operations and will not fail over to other servers in case of failure.
Proceed with fixed values and no DNS discovery? [no]:
...

可以看到命令中只指定了一个 server,所以此时 failover 并不生效。由于目前只有 Master 一个 server,所以只能这样写。后续 Replica 的节点从 client 升级到 server 之后,replica 的节点依旧只和 Master 节点上的 server 交互,而不会和 replica 上面的 server 交互。

同时,当新的 server 节点加入以及已有节点停用时,还需要手动更新 server list 以使 client 能连接到至少一个 server 上。

总之很麻烦,不推荐这种手动指定的配置。

3.3. 将新节点升级为 Replica

dnf install ipa-server ipa-server-dns 安装 server 端相关的包。

打开防火墙:

firewall-cmd --add-service={ntp,dns,freeipa-4}
firewall-cmd --add-service={ntp,dns,freeipa-4} --permanent

在 /etc/hosts 中添加一条:

192.168.2.97 b.ipa.test.local

执行 Replica 初始化:

$ ipa-replica-install --setup-ca --setup-dns --no-forwarders
Lookup failed: Preferred host serverb.ipa.jggroup.cn does not provide DNS.
...
Done.
The ipa-replica-install command was successful

--setup-ca 表示也给 CA 相关的服务创建一个 Replica,如果不带这个参数那么 ipa-replica-install 执行完后会特意提示给 Master 上的 CA 也建一个 Replica:

...
WARNING: The CA service is only installed on one server (idm.corp.example.com).
It is strongly recommended to install it on another server.
Run ipa-ca-install(1) on another master to accomplish this.
...

--setup-dns --no-forwarders 表示在这台机器上也启用内置的 DNS 并且不启用 DNS forwarder 功能 (需要的话可以再在 WebUI 里面开)。

第 2 行的 Lookup failed 表示在 Replica 上找不到 DNS 服务,因为之前在 Replica 机器上只装了 client,而 client 不需要带 DNS,所以有这个报错很正常。选项里的 --setup-dns 就是为了在 Replica 上安装一个 DNS 服务。

这里需要注意,如果在安装过程中把 DNS 地址配成了 a.ipa.test.local 的地址,由于 a 机器上的 DNS 支持 DNSSEC 这个功能,所以 /etc/named/ipa-options-ext.conf 中可以看到 dnssec-validation yes; 打开了 DNSSEC。此时,如果添加了其他不支持 DNSSEC 的 forwarder,那么 b.ipa.test.local 将无法从这些不支持 DNSSEC 的 forwarder 上解析 IP。当然,配好了也可以手动在 ipa-options-ext.conf 中关闭这个功能,改完记得 systemdtl restart named-pkcs11.service 重启服务。

至此,Replica 配置完成。

4. 确认 Master 和 Replica 的状态

在 Master 和 Replica 上都执行 ipactl status 应该得到相同的如下输出:

$ ipactl status
Directory Service: RUNNING
krb5kdc Service: RUNNING
kadmin Service: RUNNING
named Service: RUNNING
httpd Service: RUNNING
ipa-custodia Service: RUNNING
pki-tomcatd Service: RUNNING
ipa-otpd Service: RUNNING
ipa-dnskeysyncd Service: RUNNING
ipa: INFO: The ipactl command was successful

可以看到 9 个服务正在运行。两台机器一致则配置 Replica 成功。

FreeIPA 还提供了健康检查程序,常用的几个命令有:

  • ipa-healthcheck --output-type { human | JSON }: 以人类可读或 JSON 格式输出结果
  • ipa-healthcheck --output-file <file>: 将结果保存到文件

5. 删除 FreeIPA Server

这节和下一节的区别在于,按照这一节的操作走,一步步确认完,可以删除集群内任意一个节点。而下一节适用于快速删除一个 Replica。

以卸载 b.ipa.test.local 上安装的 FreeIPA Server 为例。

确认操作执行前需要先获取管理员身份凭证:

[root@b ~]# kinit admin
Password for [email protected]:

5.1. 确保 b 不是唯一的 DNS 服务器

如果 FreeIPA 集群使用了 FreeIPA 集成的 DNS,卸载前,需要确保 b 并不是集群中唯一的 DNS 服务器:

[root@b ~]# ipa server-role-find --role 'DNS server'
----------------------
2 server roles matched
----------------------
  Server name: a.ipa.test.local
  Role name: DNS server
  Role status: enabled

  Server name: b.ipa.test.local
  Role name: DNS server
  Role status: enabled
----------------------------
Number of entries returned 2
----------------------------

如果 b 是集群中唯一的 DNS 服务器,需要先用 ipa-dns-install 程序将 DNS 服务器角色添加到另一台 FreeIPA 服务器。

5.2. 确保 b 不是唯一的 CA

5.2.1. 确保 b 不是唯一的 CA 服务器

如果 FreeIPA 集群使用了 FreeIPA 集成的 CA,卸载前,需要确保 b 并不是集群中唯一的 CA 服务器:

[root@b ~]# ipa server-role-find --role 'CA server'
----------------------
2 server roles matched
----------------------
  Server name: a.ipa.test.local
  Role name: CA server
  Role status: enabled

  Server name: b.ipa.test.local
  Role name: CA server
  Role status: enabled
----------------------------
Number of entries returned 2
----------------------------

如果 b 是集群中唯一的 CA 服务器,需要先用 ipa-ca-install 程序将 CA 服务器角色添加到另一台 FreeIPA 服务器。

5.2.2. 确保 b 不是唯一的密钥恢复机构 (KRA) 服务器

如果 FreeIPA 集群使用了 vault,卸载前,需要确保 b 并不是集群中唯一启用了 KRA 服务器:

[root@b ~]# ipa server-role-find --role 'KRA server'
----------------------
2 server roles matched
----------------------
  Server name: a.ipa.test.local
  Role name: KRA server
  Role status: absent

  Server name: b.ipa.test.local
  Role name: KRA server
  Role status: absent
----------------------------
Number of entries returned 2
----------------------------

如果 b 是集群中唯一的 KRA 服务器,需要先用 ipa-kra-install 程序将 CA 服务器角色添加到另一台 FreeIPA 服务器。

5.2.3. 确保 b 不是 CA 续订服务器

有下面的输出显示,目前 a 是 CA 续订服务器:

[root@b ~]# ipa config-show | grep 'CA renewal'
  IPA CA renewal master: a.ipa.test.local

如果 b 是 CA 续订服务器,输出就是这样的:

[root@b ~]# ipa config-show | grep 'CA renewal'
  IPA CA renewal master: b.ipa.test.local

需要修改 CA 续订服务器到其他节点上,比如 a:

[root@b ~]$ ipa config-mod --ca-renewal-master-server a.idm.test.local | grep 'CA renewal'
  IPA CA renewal master: a.idm.test.local

需要注意,服务器必须具有 CA 角色才能成为 CA 续订服务器。

再继续下一步。

5.2.4. 确保 b 不是当前撤销证书列表 (CRL) 的发布者

下面的输出显示 b 不是 CRL 的发布者:

[root@b ~]# ipa-crlgen-manage status
CRL generation: disabled
The ipa-crlgen-manage command was successful

如果 b 是 CRL 的发布者,那么输出就是类似这样的:

[root@b ~]# ipa-crlgen-manage status
CRL generation: enabled
...

此时需要先取消 b 的 CRL 发布者的身份:

[root@b ~]# ipa-crlgen-manage disable
Stopping pki-tomcatd
Editing /var/lib/pki/pki-tomcat/conf/ca/CS.cfg
Starting pki-tomcatd
Editing /etc/httpd/conf.d/ipa-pki-proxy.conf
Restarting httpd
CRL generation disabled on the local host. Please make sure to configure CRL generation on another master with ipa-crlgen-manage enable.
The ipa-crlgen-manage command was successful

再在 a 上启用 CRL 发布者的身份:

[root@a ~]# ipa-crlgen-manage enable
Stopping pki-tomcatd
Editing /var/lib/pki/pki-tomcat/conf/ca/CS.cfg
Starting pki-tomcatd
Editing /etc/httpd/conf.d/ipa-pki-proxy.conf
Restarting httpd
Forcing CRL update
CRL generation enabled on the local host. Please make sure to have only a single CRL generation master.
The ipa-crlgen-manage command was successful

[root@a ~]# ipa-crlgen-manage status
CRL generation: enabled
...

再继续下一步。

5.3. 确认 b 不是集群内唯一分配 DNA ID 的服务器

如果用户不多,b 可能并没有被分配 DNA ID Range,就像这样的:

[root@servera ~]# ipa-replica-manage dnarange-show
servera.ipa.jggroup.cn: 992200002-992399999
serverb.ipa.jggroup.cn: No range set

但如果 ssh 登录到 b 上执行 ipa user-add test_idm_user 命令,这会让 b 创建一个新用户,那么 b 也就有了 DNA ID Range:

[root@servera ~]# ipa-replica-manage dnarange-show
servera.ipa.jggroup.cn: 992200002-992300499
serverb.ipa.jggroup.cn: 992300501-992399999

但是不论 b 有没有 DNA ID Range 都不重要,只要 b 不是唯一一个有 DNA ID Range 的服务器即可。如果 b 是唯一一个有 DNA ID Range 的服务器,则只需要再在集群中的其他节点上任意创建一个新用户,即可让这台机器有 DNA ID Range。

5.4. 从集群中删除 b

RedHat 推荐的命令是先用 ipa server-del ... 从集群中删除服务器,再卸载 Server 程序:

[root@b ~]# ipa server-del b.ipa.test.local
[root@b ~]# ipa-server-install --uninstall
...
Are you sure you want to continue with the uninstall procedure? [no]: yes

虽然在 man page 和 google 中都没搜到 ipa server-del ...ipa-replica-manage del ... 在行为上有什么不同,但是 FreeIPA Server 能被正常删除。

最后在上游服务器中删除指向 b.ipa.test.local 的 DNS 记录。

至此卸载完成。

6. 删除一个 Replica

这节和上一节的区别在于,这一节适用于快速删除一个 Replica。而按照上一节的操作走,一步步确认完,可以删除集群内任意一个节点。

以下操作均在 Master 上完成。

先登入 Master:

$ kinit admin
Password for [email protected]:

$ klist
Ticket cache: KCM:0
Default principal: [email protected]

Valid starting     Expires            Service principal
... 这里显示目前的会话情况

查看现有 replica 的信息:

$ ipa-replica-manage list
a.ipa.test.local: master
b.ipa.test.local: master

以删除 Replica b.ipa.test.local 为例:

$ ipa-replica-manage del b.ipa.test.local
Updating DNS system records
------------------------------------------
Deleted IPA server "b.ipa.test.local"
------------------------------------------

这样 Master 就移除了一个 Replica。

再在被移除的 Replica 上执行 ipa-server-install --uninstall 以删除被移除的 Replica 的 server 部分。

至此,集群中的一个 Replica 已被删除。

7. 备份数据

全服务器备份:

  • 包含与 IdM 相关的所有服务器配置文件,以及 LDAP 数据交换格式 (LDIF) 文件中的 LDAP 数据
  • IdM 服务必须离线
  • 适合从头开始重建 FreeIPA 部署

数据备份:

  • 在 LDIF 文件和复制更改日志中包含 LDAP 数据
  • FreeIPA 服务可以为在线或者离线
  • 适用于 将 FreeIPA 数据恢复到一个过去的状态

7.1. 备份文件命名规则

FreeIPA 备份文件以 .tar 存档的格式保存,默认放在 /var/lib/ipa/backup 目录下。

全服务器备份文件:

  • 所在的父目录的名称格式为: ipa-full-<YEAR-MM-DD-HH-MM-SS>
  • 备份文件的文件名为 ipa-full.tar
[root@a ~]# ls -lh /var/lib/ipa/backup/ipa-full-2023-05-21-09-00-09/
total 4.7M
-rw-r--r-- 1 root root  165 May 21 08:59 header
-rw-r--r-- 1 root root 4.7M May 21 09:00 ipa-full.tar

数据备份文件:

  • 所在的父目录的名称格式为 ipa-data-<YEAR-MM-DD-HH-MM-SS>
  • 备份文件的文件名为 ipa-data.tar
[root@a ~]# ls -lh /var/lib/ipa/backup/ipa-data-2023-05-21-08-14-38/
total 2.2M
-rw-r--r-- 1 root root  165 May 21 08:14 header
-rw-r--r-- 1 root root 2.2M May 21 08:14 ipa-data.tar

卸载 FreeIPA 服务器不会自动删除任何备份文件。

7.2. 创建备份前的注意事项

  • 执行 ipa-backup 程序的用户必须有 root 权限
  • ipa-backup 程序默认以离线模式运行,程序运行中停止所有 FreeIPA 服务。备份完成后 FreeIPA 服务会被自动重启
  • 全服务器备份必须始终在 FreeIPA 服务离线的情况下运行,但可以执行 ipa-backup --data --online 仅创建数据备份
  • ipa-backup 程序默认在包含 /var/lib/ipa/backup 目录的文件系统中创建备份。红帽建议在独立于 FreeIPA 的生产文件系统之外的文件系统中定期创建备份
  • 执行需要停止 FreeIPA 服务的备份时,可以考虑使用 hidden replica 来避免停止服务
  • 从 RHEL 8.3.0 开始,ipa-backup 程序会检查 FreeIPA Server 集群中是否安装了所有组件。如,证书颁发机构(CA)、域名系统 (DNS) 和密钥恢复代理 (KRA) 等应当全部被安装在要被备份的服务器上。如果被备份的服务器没有安装所有组件,ipa-backup 程序会报错后退出。因为这样创建出的备份不能包含所有组件的数据,不足以完全恢复集群
  • 可以使用 ipa-backup --disable-role-check 命令绕过对于 FreeIPA Server 组件应当全部被安装的检查。但这样生成的备份不会包含完全恢复 FreeIPA 所需的所有数据

7.3. 创建备份

让 FreeIPA Server 离线并创建全服务器备份:

[root@a ~]# ipa-backup
Preparing backup on a.ipa.test.local
Local roles match globally used roles, proceeding.
Stopping IPA services
Backing up ipaca in IPA-TEST-LOCAL to LDIF
Backing up userRoot in IPA-TEST-LOCAL to LDIF
Backing up IPA-TEST-LOCAL
Backing up files
Starting IPA service
Backed up to /var/lib/ipa/backup/ipa-full-2023-05-21-09-00-09
The ipa-backup command was successful

让 FreeIPA Server 离线并创建数据备份:

[root@a ~]# ipa-backup --data

让 FreeIPA Server 离线并创建带有全部日志文件的全服务器备份:

[root@a ~]# ipa-backup --logs

FreeIPA Server 不离线并创建数据备份:

[root@a ~]# ipa-backup --data --online

8. 利用备份解决故障

使用全服务器备份可以解决:

  • 所有 FreeIPA Server 都出现故障或所有 CA 实例都丢失
  • 脱离集群的 FreeIPA 服务器升级失败导致 FreeIPA 数据被破坏

使用数据备份可以解决:

  • 对 LDAP 内容执行了错误的操作

注: 硬件问题或升级失败的首选解决方案是重建一个 Replica

8.1. 利用备份数据恢复服务器前的注意事项

假设,创建备份数据的服务器为 A,要执行数据恢复的服务器为 B。

  • A 和 B 可以是同一台机器。但在 A 和 B 不是同一台机器时,A 和 B 必须有:
    • 相同的主机名
    • 相同的 IP 地址
    • 同一版本的 IdM 软件
  • 利用全服务器备份文件恢复服务器前,先在 B 上卸载 FreeIPA Server,并使用与卸载前相同的配置重新安装 FreeIPA Server
  • 如果 B 属于某个集群,那么在 B 被恢复之后,整个集群需要以 B 所包含的信息为基准重新初始化
  • 如果集群中的某台服务器掉线,那么最好的方法是重建一个 Replica 加入集群,而不是从全服务器备份中恢复服务器。这可以避免整个集群重新初始化
  • 备份和恢复只能在命令行操作,在 Web UI 中不可用
  • 备份数据不能位于 /tmp 或 /var/tmp 目录下。FreeIPA Server 使用 PrivateTmp 目录,无法访问 /tmp 或 /var/tmp 目录

8.2. 利用备份数据恢复服务器

操作执行前需要先获取管理员身份凭证:

[root@b ~]# kinit admin
Password for [email protected]:

第一步,使用备份的数据恢复第一台机器。

如果备份目录位于默认 /var/lib/ipa/backup 位置,则只输入目录名称:

[root@a ~]# ipa-restore ipa-full-2023-05-21-09-00-09

如果备份目录不在默认位置,请输入其完整路径:

[root@a ~]# ipa-restore /mybackups/ipa-full-2023-05-21-09-00-09

恢复前需要输入一遍 Directory Manager 的密码,确认所有数据都会被覆盖,提示所有的服务器都需要根据这台机器重新初始化,最后关闭 FreeIPA 服务、恢复备份再在本机上重新启动 FreeIPA 服务。

第二步,重新初始化连接到被恢复数据的机器的所有机器。

整个集群可以根据 Replica 拓扑与 CA 拓扑生成两张连通有向图。重新初始化的基本思路是,以被初始化的第一个节点为根,在遍历 Replica 拓扑的过程中初始化每个节点上的 Replica,在遍历 CA 拓扑的过程中初始化每个节点上的 CA。

在 a 上以 domain 为后缀查看集群拓扑结构:

[root@a ~]# ipa topologysegment-find domain
-----------------
1 segment matched
-----------------
  Segment name: a.ipa.test.local-to-b.ipa.test.local
  Left node: a.ipa.test.local
  Right node: b.ipa.test.local
  Connectivity: both
----------------------------
Number of entries returned 1
----------------------------

可以看到,案例集群的 Replica 拓扑极为简单,两个节点双向连通。

用 ssh 连接到 b 上,重建 b 的 Replica:

[root@b ~]# ipa-replica-manage re-initialize --from=a.ipa.test.local
Update in progress, 2 seconds elapsed
Update succeeded

在 a 上以 ca 为后缀,列出所有的拓扑片段:

[root@a ~]# ipa topologysegment-find ca
-----------------
1 segment matched
-----------------
  Segment name: a.ipa.test.local-to-b.ipa.test.local
  Left node: a.ipa.test.local
  Right node: b.ipa.test.local
  Connectivity: both
----------------------------
Number of entries returned 1
----------------------------

用 ssh 连接到 b 上,重建 b 的 CA:

[root@b ~]# ipa-csreplica-manage re-initialize --from=a.ipa.test.local
Directory Manager password:

Update in progress, 2 seconds elapsed
Update succeeded

第三步,清除 SSSD 的缓存,避免因为数据无效而导致身份验证问题:

  • 停止 SSSD 服务 systemctl stop sssd
  • 从 SSSD 中删除所有缓存的内容 sss_cache -E
  • 启动 SSSD 服务 systemctl start sssd

第四步,重启服务器。



Last Update: 2023-12-05 Tue 15:20

Generated by: Emacs 28.2 (Org mode 9.5.5)   Contact: [email protected]

若正文中无特殊说明,本站内容遵循: 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议